package Lee_code;

public class Lee_733 {

    public static int row;
    public static int column;
    public static int new_color;
    public static int old_color;
    public int[][] floodFill(int[][] image, int sr, int sc, int color) {

        row=image.length;
        column= image[0].length;
        new_color = color;
        old_color = image[sr][sc];

        dfs(image, sr, sc);

        return image;
    }
    public static void dfs(int[][] image, int sr, int sc)
    {
        if(sr<0||sr<0||sr>row-1||sc>column-1||image[sr][sc]!=old_color||image[sr][sc]==new_color)
        {
            return;
        }
        image[sr][sc]=new_color;
        dfs(image, sr+1, sc);
        dfs(image, sr-1, sc);
        dfs(image, sr, sc+1);
        dfs(image, sr, sc-1);

    }

    public static void main(String[] args) {

    }
}
